package com.atom.module.draw.dialogs

import androidx.appcompat.app.AlertDialog
import com.atom.module.draw.R
import com.atom.module.draw.activities.DrawActivity
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.atom.module.draw.helpers.JPG
import com.atom.module.draw.helpers.PNG
import com.atom.module.draw.helpers.SVG
import java.io.File

class SaveImageDialog(
    val activity: DrawActivity,
    val defaultPath: String,
    val defaultFilename: String,
    val defaultExtension: String,
    val hidePath: Boolean,
    callback: (fullPath: String, filename: String, extension: String) -> Unit
) {
    private val SIMPLE_DRAW = "Simple Draw"

    init {
//        val initialFilename = getInitialFilename()
//        var folder =
//            if (defaultPath.isEmpty()) "${activity.internalStoragePath}/$SIMPLE_DRAW" else defaultPath
//
//        activity
//        val binding: DialogSaveImageBinding = DataBindingUtil.inflate(
//            activity.layoutInflater,
//            R.layout.dialog_save_image,
//            null,
//            false
//        )
//        binding.saveImageFilename.setText(initialFilename)
//        binding.saveImageRadioGroup.check(
//            when (defaultExtension) {
//                JPG -> R.id.save_image_radio_jpg
//                SVG -> R.id.save_image_radio_svg
//                else -> R.id.save_image_radio_png
//            }
//        )
//
//        if (hidePath) {
//            binding.saveImagePathLabel.beGone()
//            binding.saveImagePath.beGone()
//        } else {
//            binding.saveImagePath.text = activity.humanizePath(folder)
//            binding.saveImagePath.setOnClickListener {
////                FilePickerDialog(activity, folder, false, showFAB = true) {
////                    binding.saveImagePath.text = activity.humanizePath(it)
////                    folder = it
////                }
//            }
//        }

//        AlertDialog.Builder(activity)
//            .setPositiveButton(R.string.ok, null)
//            .setNegativeButton(R.string.cancel, null)
//            .create().apply {
//                activity.setupDialogStuff(binding.root, this, R.string.save_as) {
//                    showKeyboard(binding.saveImageFilename)
//                    getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
//                        val filename = binding.saveImageFilename.value
//                        if (filename.isEmpty()) {
//                            activity.toast(R.string.filename_cannot_be_empty)
//                            return@setOnClickListener
//                        }
//
//                        val extension = when (binding.saveImageRadioGroup.checkedRadioButtonId) {
//                            R.id.save_image_radio_png -> PNG
//                            R.id.save_image_radio_svg -> SVG
//                            else -> JPG
//                        }
//
//                        val newPath = "${folder.trimEnd('/')}/$filename.$extension"
//                        if (!newPath.getFilenameFromPath().isAValidFilename()) {
//                            activity.toast(R.string.filename_invalid_characters)
//                            return@setOnClickListener
//                        }
//
//                        if (!hidePath && File(newPath).exists()) {
//                            val title = String.format(
//                                activity.getString(R.string.file_already_exists_overwrite),
//                                newPath.getFilenameFromPath()
//                            )
//                            ConfirmationDialog(activity, title) {
//                                callback(newPath, filename, extension)
//                                dismiss()
//                            }
//                        } else {
//                            callback(newPath, filename, extension)
//                            dismiss()
//                        }
//                    }
//                }
//            }
    }

    private fun getInitialFilename(): String {
        val newFilename = "image_${activity.getCurrentFormattedDateTime()}"
        return if (defaultFilename.isEmpty()) newFilename else defaultFilename
    }
}
